import 'package:flutter/material.dart';
import 'package:study_flutter/wyfg/project/shop/config/ser_fun.dart';
import 'package:study_flutter/wyfg/project/shop/view/home/ad_banner.dart';
import 'package:study_flutter/wyfg/project/shop/view/home/floor_goods.dart';

//import 'package:study_flutter/wyfg/project/shop/view/home/floor_recommend.dart';
import 'package:study_flutter/wyfg/project/shop/view/home/goods_recommend.dart';
import 'package:study_flutter/wyfg/project/shop/view/home/leader_phone.dart';
import 'dart:convert';
import 'package:study_flutter/wyfg/project/shop/view/home/my_swiper.dart';
import 'package:study_flutter/wyfg/project/shop/view/home/top_navigation.dart';

class WHomePage extends StatefulWidget {
  @override
  _WHomePageState createState() => _WHomePageState();
}

class _WHomePageState extends State<WHomePage>
    with AutomaticKeepAliveClientMixin {
  var text = "等待数据";

  @override
  Widget build(BuildContext context) {
    return Container(
        child: Scaffold(
            appBar: AppBar(
              title: Text("首页"),
              backgroundColor: Colors.pinkAccent,
            ),
            body: FutureBuilder(
                future: getHomePageData(),
                builder: (context, s) {
                  if (s.hasData) {
                    var dataMsg = json.decode(s.data.toString());
                    var data = dataMsg['data'];
                    List<Map> swiper = (data['slides'] as List).cast();
                    List<Map> navigationList =
                        (data['category'] as List).cast();
                    String ad_img = data['advertesPicture']['PICTURE_ADDRESS'];
                    String leaderImg = data['shopInfo']['leaderImage'];
                    String leaderPhone = data['shopInfo']['leaderPhone'];
                    List<Map> recommendList =
                        (data['recommend'] as List).cast();

                    String floor1Title =
                        data['floor1Pic']['PICTURE_ADDRESS']; //楼层1的标题图片
                    String floor2Title =
                        data['floor2Pic']['PICTURE_ADDRESS']; //楼层1的标题图片
                    String floor3Title =
                        data['floor3Pic']['PICTURE_ADDRESS']; //楼层1的标题图片
                    List<Map> floor1 =
                        (data['floor1'] as List).cast(); //楼层1商品和图片
                    List<Map> floor2 =
                        (data['floor2'] as List).cast(); //楼层1商品和图片
                    List<Map> floor3 =
                        (data['floor3'] as List).cast(); //楼层1商品和图片
                    return SingleChildScrollView(
                      child: Column(
                        children: <Widget>[
                          MySwiper(swiper),
                          TopNavigation(navigationList),
                          AdBanner(ad_img),
                          LeaderPhone(leaderImg, leaderPhone),
                          GoodsRecommend(recommendList),
//                          FloorTitle(floor1Title),
//                          FloorRecommend(floor1),
                          FloorTitle(floor1Title),
                          FloorGoods(floor1),
                          FloorTitle(floor2Title),
                          FloorGoods(floor2),
                          FloorTitle(floor3Title),
                          FloorGoods(floor3),
                        ],
                      ),
                    );
                  } else {
                    return Text("=========================");
                  }
                })));
  }

  @override
  bool get wantKeepAlive => true;
}
